#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 3010;

int mod,n;
ll fac[N],ifac[N],pw[N],S[N][N],ans,ppw[N];

ll qp(ll x,int t){ll res=1;for(;t;t>>=1,x=x*x%mod)if(t&1) res=res*x%mod;return res;}

ll calc(int x){
	ll res = 0;
	for(int i = 0;i <= x;i++) res = (res + S[x + 1][i + 1] * qp(pw[n - x],i) % mod) % mod;
	res = res * fac[n] % mod * ifac[x] % mod * ifac[n - x] % mod * qp(2,ppw[n - x]) % mod; return res;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,mod = in; for(int i = (fac[0] = pw[0] = ppw[0] = 1);i <= n;i++) fac[i] = fac[i-1] * i % mod,pw[i] = pw[i-1] * 2 % mod,ppw[i] = ppw[i-1] * 2 % (mod - 1);
	ifac[n] = qp(fac[n],mod-2); for(int i = n - 1;i >= 0;i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
	S[0][0] = 1;for(int i = 1;i <= n + 1;i++) for(int j = 1;j <= i;j++) S[i][j] = (S[i-1][j-1] + S[i-1][j] * j % mod) % mod;
	for(int i = 0;i <= n;i++) ans = (ans + calc(i) * (i & 1 ? mod - 1 : 1) % mod) % mod; printf("%lld\n",ans);
	return 0;
}
